package com.rent.collectrent.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rent.collectrent.entity.BankReceipt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author news
 * *@date 2025/9/28
 */
@Mapper
@Repository
public interface BankReceiptMapper extends BaseMapper<BankReceipt> {


    /**
     * 分页查询未使用的银行收款记录
     */
    List<BankReceipt> selectUnusedReceipts(@Param("offset") int offset,
                                           @Param("limit") int limit);

    /**
     * 更新银行收款使用状态和金额
     */
    int updateUsageStatus(@Param("id") Long id,
                          @Param("usedAmount") BigDecimal usedAmount,
                          @Param("usageStatus") BankReceipt.UsageStatus usageStatus);

    /**
     * 根据ID和版本号更新（乐观锁）
     */
    int updateWithLock(@Param("id") Long id,
                       @Param("version") Integer version,
                       @Param("usedAmount") BigDecimal usedAmount,
                       @Param("usageStatus") BankReceipt.UsageStatus usageStatus);

}
